package tree;

/**
 * @author way
 * @create 2025-02-16 19:02
 */
public class _538_convertBST {
    int sum;

    public TreeNode convertBST(TreeNode root) {
        sum = 0;
        deal(root);
        return root;
    }

    private void deal(TreeNode root) {
        if (root == null) return;

        deal(root.right);
        sum += root.val;
        root.val = sum;
        deal(root.left);
    }
}
